from rest_framework import mixins
from rest_framework import permissions, status
from rest_framework.decorators import permission_classes
from rest_framework.viewsets import GenericViewSet

from backend.helper import Response
from operations.serializers import FollowSerializer
from users.models import UserInfo


@permission_classes([permissions.IsAuthenticated])
class FollowAPIView(GenericViewSet, mixins.CreateModelMixin):
    queryset = UserInfo.objects.all()
    serializer_class = FollowSerializer

    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        return Response(data={
            'success': True,
            'code': 200,
            'msg': 'success'
        }, status=status.HTTP_200_OK, headers=headers)
